#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
@Author          : ricsy
@File            : code.py
@Create Time     : 2025/6/18 05:23
@Last Modified   :
@Description     :
"""

from docutils.nodes import literal_block

from theme_customizer.base import BaseCustomizer


class CodeBlockManager(BaseCustomizer):
    """代码块"""

    def apply(self):
        pass

    def add_linenos(self, doctree):
        """生成行号"""
        for node in doctree.traverse(literal_block):
            if (
                "language" in node.attributes
                and node.attributes["language"]
                in self.app.config.myst_number_code_blocks
            ):
                # 添加代码块行号，解决启用 myst-nb 插件解析.md 文件后 myst_number_code_blocks 配置无效问题
                node.attributes["linenos"] = True
